// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CEventSink.
//   $Id$



// EventSink.h: interface for the CEventSink class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_EVENTSINK_H__47E6CB31_D9EA_4DC2_AF61_429BF0DBB99B__INCLUDED_)
#define AFX_EVENTSINK_H__47E6CB31_D9EA_4DC2_AF61_429BF0DBB99B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "resource.h"
#include "mshtmdid.h"

#include "FormControl.h"
class CXFormsElement;
class CXFormsXFormsElement;

//to be called by CEventSink, upon invocation, 
//	implement this interface.
class IEventSinkHandler;

class ATL_NO_VTABLE CEventSink :  
    public CComObjectRootEx<CComSingleThreadModel>, 
    public CComCoClass<CEventSink, &CLSID_EventSink>, 
    public IDispatchImpl<IEventSink, &IID_IEventSink, &LIBID_XFORMSLib> 
{ 
public: 
	//CComObject<CBinaryBehavior>* m_pBehavior; 
static unsigned long esCount;
	CEventSink() : 
		m_pFormControl(NULL)
		,m_pControl(NULL)
		,m_vdEventDetails(NULL)
		,m_bHandleThroughHandleEvent(false)
		,m_pEventFunc(NULL)
		,m_pHandler(0)
	{
#ifdef COUNT_EVENTSINKS
		++esCount;
#endif
	}
		virtual ~CEventSink()
		{
#ifdef COUNT_EVENTSINKS
			--esCount;
#endif
		}

DECLARE_REGISTRY_RESOURCEID(IDR_EVENTSINK) 
DECLARE_NOT_AGGREGATABLE(CEventSink) 

BEGIN_COM_MAP(CEventSink) 
//    COM_INTERFACE_ENTRY2(HTMLElementEvents, IEventSink) 
	COM_INTERFACE_ENTRY(IEventSink) 
    COM_INTERFACE_ENTRY(IDispatch) 
END_COM_MAP() 

// IDispatchImpl override 
    STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
			DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
	
	//Temp, As controls and events are getting more complex, it is necessarry
	//	to start handling events in a better way.  this bool is here so that
	//	I can gradually restructure the events system without having to 
	//	write event handling code for every single class.

	bool m_bHandleThroughHandleEvent; 

	void SetHandler(IEventSinkHandler * pHandler);
	//this should be abolished
	CFormControl* m_pFormControl; 
	//These two should be amalgamated, and use the IEventSinkHandler interface, 
	//	unfortunately, m_pControl->m_pControl in Invoke makes this difficult.
	//	I think it's probably redundant, if not, it will be once we change the date control.
	CXFormsElement * m_pControl;
private:
	IEventSinkHandler * m_pHandler;
	LPVOID m_vdEventDetails;
	HRESULT (_stdcall*m_pEventFunc)(LPVOID,LPDISPATCH);

}; 

OBJECT_ENTRY_AUTO(__uuidof(EventSink), CEventSink)
#endif // !defined(AFX_EVENTSINK_H__47E6CB31_D9EA_4DC2_AF61_429BF0DBB99B__INCLUDED_)
